<template>
  <div class="app-container">
    <el-row :gutter="20">

      <el-col :span="mainwidth" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

          <el-form-item label="时间类型" prop="status">
            <el-select
              v-model="queryParams.timetype"
              placeholder="时间类型"
              clearable
              size="small"
              style="width: 130px"
            >
              <el-option
                v-for="dict in timetypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-date-picker
              v-model="selTime"
              type="daterange"
              :picker-options="pickerOptions"
              range-separator="至"
              value-format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 260px"
              align="right">
            </el-date-picker>
          </el-form-item>
        </el-form>

      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom: -10px;line-height:35px">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-input
              v-model="queryParams.value"
              placeholder="查询值"
              clearable
              size="small"
              style="width: 350px"
              @keyup.enter.native="handleQuery"
            >
              <el-select
                v-model="queryParams.type"
                placeholder="查询条件"
                clearable
                slot="prepend"
                style="width: 110px;background-color: transparent;color: black;"
              >
                <el-option
                  v-for="dict in typeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-input>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="发货状态" style="margin-bottom: 10px;line-height:35px">
              <el-select v-model="queryParams.ODY_dsID" multiple clearable placeholder="请选择" size="small" >
                <el-option
                  v-for="dict in ShipStateOption"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" v-hasPermi="['yunze:FhglOrderDelivery:list']"
                         @queryTable="getList"
                         :columns="columns"></right-toolbar>
        </el-row>
      </el-form>

        <el-table v-loading="loading" :data="DataList" @selection-change="handleSelectionChange">
          <el-table-column :label="columns[0].label" align="center" prop="Time" v-if="columns[0].visible"/>
          <el-table-column :label="columns[1].label" align="center" prop="ODY_nocID" v-if="columns[1].visible">
            <template slot-scope="scope">
              {{ tools.getDkeyValue(contractNatureOption, scope.row.ODY_nocID) }}
            </template>
          </el-table-column>
          <el-table-column :label="columns[2].label" align="center" prop="CoName" v-if="columns[2].visible"/>
          <el-table-column :label="columns[3].label" align="center" prop="NAME" v-if="columns[3].visible"/>
          <el-table-column :label="columns[4].label" align="center" prop="Dio_DsID" v-if="columns[4].visible">
            <template slot-scope="scope">
              {{ tools.getDkeyValue(Remittance_State, scope.row.Dio_DsID) }}
            </template>
          </el-table-column>
          <el-table-column :label="columns[5].label" align="center" prop="ODY_dsID" v-if="columns[5].visible">
            <template slot-scope="scope">
              <span
                :class="getColor(scope.row.ODY_dsID)">{{
                  tools.getDkeyValue(ShipStateOption, scope.row.ODY_dsID)
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="columns[6].label" align="center" prop="ODY_Estimated_Time"
                           v-if="columns[6].visible"/>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">

              <el-dropdown>
                <el-button type="primary" size="small">
                  操作<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-hasPermi="['yunze:FhglOrderDelivery:add']"
                                    @click.native="handleUpdate(scope.row,'Add')">载入发货申请
                  </el-dropdown-item>
                  <el-dropdown-item v-hasPermi="['yunze:FhglOrderDelivery:find']"
                                    @click.native="handleUpdate(scope.row,'Find')">详情
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>

              <!-- <el-button
                 size="mini"
                 type="text"
                 icon="el-icon-edit"
                 @click="onPreview(scope.row)"
               >图片查看
               </el-button>-->

            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>


    <!-- 新增发货申请 -->
    <el-drawer
      :with-header="false"
      :visible.sync="show_ds"
      :close-on-click-modal="false"
      size="90%">
      <el-scrollbar style="height:1000px;min-height: 100%;">
        <ShooingAdd ref="shooingAdd"
                    :CustomerOneCategoryOption="CustomerOneCategoryOption"
                    :CustomerTowCategoryOption="CustomerTowCategoryOption"
                    :Large_classification="Large_classification"
                    :Small_classification="Small_classification"
                    :DeliveryTypeOption="DeliveryTypeOption"
                    :DeliverySelectionTypeOption="DeliverySelectionTypeOption"
                    :DeliveryMethodOption="DeliveryMethodOption"
                    :ShippingMethodOption="ShippingMethodOption"
                    :contractNatureOption="contractNatureOption"
                    :firmAccountOption="firmAccountOption"
                    :CourierCompanyOptions="CourierCompanyOptions"
                    :CustomerGradeOption="CustomerGradeOption"
                    :selFindoptions="selFindoptions"
                    :form="form"
                    :getTowClass="getTowClass"
                    :commodity="commodity"
                    :window="window"
                    :CustomerAdd="CustomerAdd"
                    :CustomerEdie="CustomerEdie"
                    :HeadquartersnOrmalOption="HeadquartersnOrmalOption"
                    :SubAdd="SubAdd"
                    :loadingSelOption="loadingSelOption"
                    :show_ds="show_ds"
                    :execute="execute"
                    :Editexecute="Editexecute"
                    @SetObj="SetObj"
                    :SubUpd="SubUpd"
                    :OperationType="OperationType"
        />
        <div style="height: 2000px;"></div>
      </el-scrollbar>
    </el-drawer>

    <!-- 合同发货详情查看 -->
    <el-drawer
      :with-header="false"
      :visible.sync="show_dsArr"
      :close-on-click-modal="false"
      size="90%">
      <el-scrollbar style="height:1000px;min-height: 100%;">
        <DetailsAdd ref="DetailsAdd"
                    :CustomerOneCategoryOption="CustomerOneCategoryOption"
                    :CustomerTowCategoryOption="CustomerTowCategoryOption"
                    :Large_classification="Large_classification"
                    :Small_classification="Small_classification"
                    :DeliveryTypeOption="DeliveryTypeOption"
                    :DeliverySelectionTypeOption="DeliverySelectionTypeOption"
                    :DeliveryMethodOption="DeliveryMethodOption"
                    :ShippingMethodOption="ShippingMethodOption"
                    :contractNatureOption="contractNatureOption"
                    :firmAccountOption="firmAccountOption"
                    :CourierCompanyOptions="CourierCompanyOptions"
                    :CustomerGradeOption="CustomerGradeOption"
                    :selFindoptions="selFindoptions"
                    :form="form"
                    :getTowClass="getTowClass"
                    :commodity="commodity"
                    :window="window"
                    :CustomerAdd="CustomerAdd"
                    :CustomerEdie="CustomerEdie"
                    :HeadquartersnOrmalOption="HeadquartersnOrmalOption"
                    :SubAdd="SubAdd"
                    :loadingSelOption="loadingSelOption"
                    :show_dsArr="show_dsArr"
                    :execute="execute"
                    :Editexecute="Editexecute"
                    @SetObj="SetObj"
                    :SubUpd="SubUpd"
                    :OperationType="OperationType"
                    :SAFL_SANIDArr="SAFL_SANIDArr"

        />
        <div style="height: 2000px;"></div>
      </el-scrollbar>
    </el-drawer>


  </div>
</template>


<script>
import {regionData, regionDataPlus, CodeToText, TextToCode} from 'element-china-area-data';
import {getList, getODYContractID} from "@/api/yunze/FHGL/OrderDelivery/OrderDelivery";
import {add} from "@/api/yunze/FHGL/FhglShippingApplication";
import {findSalesPartner} from "@/api/yunze/XSGL/customer/customer";
import {Administration} from "@/api/yunze/Dictionaries/type";
import ShooingAdd from '../ShippingApplication/ShooingAdd';
import DetailsAdd from '../OrderDelivery/details';
import tools from "@/utils/yunze/tools";
import {ExpressSelDate} from "@/api/yunze/FHGL/FhglExpressDelivery";


export default {
  name: "OrderDelivery",
  components: {
    ShooingAdd,
    DetailsAdd,
  },
  data() {
    return {
      IsDisabled: true,//是否禁用
      checkAll: false,
      checkedCities: [],
      cities: [],//'上海', '北京', '广州', '深圳'
      isIndeterminate: false,
      cityOptions: [],//'上海', '北京', '广州', '深圳'
      selName: '',//客户名称检索
      hide_show: false,//隐藏
      DeliveryTypeOption: [], //数据字典 发货类型
      DeliverySelectionTypeOption: [], //数据字典 发货选择类型
      DeliveryMethodOption: [], //数据字典 发货方式
      ShippingMethodOption: [],//数据字典 运费方式
      contractNatureOption: [],  //数据字典 订单合同发货信息 合同性质
      firmAccountOption: [], //数据字典 销售单位信息
      CourierCompanyOptions: [],//数据字典 快递公司信息
      HeadquartersOption: [], //  总部门所有人
      HeadquartersnOrmalOption: [], //  总部门所有人 【状态正常 】
      loadingSelOption: false,//是否 加载 查询客户信息框


      // 大分类
      Large_classification: [],
      // 小分类
      Small_classification: [],
      //回显展示
      innerDrawer: false,

      DivideBool: false,//划分按钮
      RecycleBool: false,//回收按钮


      CustomerOption: [],//根据 查询条件加载的销售客户信息
      PeopleOption: [],//根据 查询条件加载的 客户联系人
      AccountOption: [],//根据 查询条件加载的 客户地址


      CustomerAccountData_Cache: [],//账户信息 表格 修改时 缓存 最初加载数据
      CustomerAccountData_delArr: [],//账户 数据库 删除的id
      CustomerAccountData: [
        /* {
           Cat_ID: 'AAAAA',
           Cat_Name: 'AAAAAB',
           Cat_Bank_Name: 'AAAAAC',
           Cat_Number: 'AAAAAD',
           Cat_CoID: 'AAAAAe',
           Cat_User_Name: 'AAAAAf',
           Cat_Zip_Code: 'AAAAAg',
           Cat_Address: 'AAAAAh',
           Cat_atId: '1',
         }*/

      ],//账户信息 表格
      Accounttitle: '',
      Account_show: false,//账户信息 显示
      addAccountBtn: false,
      editAccountBtn: false,
      // 账户信息 map
      Accountform: {
        Cat_ID: null,
        Cat_Name: null,
        Cat_Bank_Name: null,
        Cat_Number: null,
        Cat_CoID: null,
        Cat_User_Name: null,
        Cat_Zip_Code: null,
        Cat_Address: null,
        Cat_atId: '1',
      },

      // 商品表参数
      commodity: {
        Cy_Sort: null,
        Cy_Category: null,
      },
      AccountActiveNames: ['0'],//面板默认 展开 【账号】
      PeopleActiveNames: ['0'],//面板默认 展开 【联系人】

      // 时间查询类型 数据字典
      timetypeOptions: [],
      selTime: '',//时间选择
      //客户联系人 数组

      CustomerPeopleData_delArr: [],//联系人 数据库 删除的id
      CustomerPeopleData_Cache: [],//联系人 表格 修改时 缓存 最初加载数据
      CustomerPeopleData: [],
      //联系人 表格
      Peopletitle: '',
      People_show: false,//账户信息 显示
      CustomerDivide_show: false,//客户划分 显示
      addPeopleBtn: false,
      editPeopleBtn: false,
      //划分联系人
      CtDivideform: {
        sales_id: null,
        CDdeptIdArr: [],
      },

      // 客户联系人 map
      Peopleform: {
        id: null,
        cu_id: null,
        name: null,
        telephone: null,
        qq: null,
        nailed: null,
        email: null,
        remarks: null,
        job_title: null,
        state: '1',
        is_maste: '1',
        gender_id: '0',
      },

      PartnerOption: [],//合伙人
      SalesOption: [],//销售

      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },


      pickerOptionsDay: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', tools.gitData());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            picker.$emit('pick', tools.getBeforeDate(1));
          }
        }, {
          text: '一周前',
          onClick(picker) {
            picker.$emit('pick', tools.getBeforeDate(7));
          }
        }]
      },

      OperationType: 'SubAdd',//子界面执行函数 名称判断
      options: regionData,
      selFindoptions: regionDataPlus,

      Editexecute: true,//发货申请 编辑加载是否 已执行
      execute: false,//加载是否 已执行
      CodeToText: CodeToText,
      TextToCode: TextToCode,
      selectedOptions: [],
      SelselectedOptions: [],

      images: [],
      sortImages: !this.images ? [] : [].concat(this.images),
      acceptConfig: 'image/jpeg,image/png,image/jpg,image/gif',
      fileList: {},

      url: '',
      srcList: [],


      Divide_show: false,//卡划分
      Dividebtn: true,//商品代理 btn
      //商品代理企业
      treeName: undefined,
      formDivide: {
        dept_id: '',
        user_id: '',
      },


      Is_notAdd: false,
      dialogImageUrl: '',
      dialogVisible: false,
      disabled: false,

      //保存 编辑 按钮
      CustomerAdd: false,
      CustomerEdie: false,
      tools: tools,
      deptCheckStrictly: false,
      deptExpand: true,
      deptNodeAll: false,
      show_ds: false,//详情查看
      show_dsArr: false,//详情查看
      SAFL_SANIDArr: [],//已申请发货申请数组

      show_ds_Register: false,//详情查看 发货登记
      table_Online: [],//在线状态信息gradeIdArr
      DeptOptions: [],// 公司信息
      customize_whether: [],//自定义是否

      mainwidth: 24,//宽度
      option_show: false, //公司所属查询
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      //  商品 信息 数据
      CommodityList: [],
      //主界面数据
      DataList: [],

      CommodityList_delArr: [],
      // 弹出层标题
      title: "",
      // 部门树选项
      deptOptions: undefined,
      // 是否显示弹出层
      open: false,
      // 部门名称
      deptName: undefined,
      // 默认密码
      initPassword: undefined,
      // 日期范围
      dateRange: [],
      // 状态数据字典
      typeOptions: [],
      ShipStateOption: [], //数据字典 发货状态
      Remittance_State: [], //数据字典 入款状态
      //详情
      tablefrom: [],
      imgArr: [],//上传图片
      SelectImgArr: [],//  商品图片查看图片
      window: window,
      checkStateOption: [], //加载 商品出售状态
      FlowData: [],
      selIccid: [
        {
          Cat_ID: '',
          Cat_Name: 'oooop',
          Cat_Bank_Name: '',
          Cat_Number: '',
          Cat_CoID: '',
          Cat_User_Name: '',
          Cat_Zip_Code: '',
          Cat_Address: '',
          Cat_atId: '',
        }
      ],
      activeNames: [0],
      Dividetitle: '',
      //卡状态
      status_type: "",
      // 卡状态 字典
      stateOptions: [
        {
          dictLabel: ''
        }
      ],
      // 客户地址类型
      AccountAddressTypeOption: [],
      AccountPeopleStateTypeOption: [],// 客户 联系人 状态
      // 客户类型
      CustomerSortTypeOption: [],
      // 客户一级分类
      CustomerOneCategoryOption: [],
      // 客户二级分类
      CustomerTowCategoryOption: [],
      // 客户级别
      CustomerGradeOption: [],
      // 客户状态
      customerStateOptions: [],
      CustomerSourceOptions: [],// 客户 来源
      // 渠道来源 字典
      sourceOption: [],
      // 通道编码 字典
      channelCodeOptions: [],
      // 表单参数
      form: {
        SAN_ID: null,
        SAN_StyID: '1',
        SAN_CoID: null,
        SAN_CoName: null,
        SAN_Recipient_Name: null,
        SAN_Recipient_Tel: null,
        SAN_Recipient_Address: null,
        SAN_Time: tools.gitData(),
        SAN_UserID: null,
        SAN_Sender_Name: null,
        SAN_ShiptyID: '1',
        SAN_FpayType: '1',
        SAN_Tracking_Number: null,
        SAN_Express_Delivery: null,
        SAN_Delivery_Status: null,
        SAN_Delivery_Person: null,
        SAN_Remarks: null,
        SAN_Shipping_Method: null,
        SAN_Shipping_MethodArr: [],
        IsManual: '0',//手动填写
        IsManualBool: false,//手动填写 bool
        c_party_a_id: null,
        Manual_SAN_Recipient_Address: null,//手动填写 地址
        Manual_SAN_Recipient_Tel: null,//手动填写 收件人电话
        Manual_SAN_Recipient_Name: null,//手动填写 收件人
      },
      defaultProps: {
        children: "children",
        label: "label"
      },
      //当前查询参数
      Sel: {
        gradeIdArr: [],
        oneIdArr: [],
        TowIdArr: [],
        sourceIdArr: [],
        province: null,
        city: null,
        district: null,
        c_name: null,
      },
      // 查询参数
      queryParams: {
        ODY_dsID: ['1', '2'],
        pageNum: 1,
        pageSize: 10,
        type: null,
        value: null,
        SAFL_SANID: null,
        SAFL_ODYContractID: null,
      },

      // 列信息
      columns: [
        {key: 0, label: `合同日期`, visible: true},
        {key: 1, label: `合同性质`, visible: true},
        {key: 2, label: `企业`, visible: true},
        {key: 3, label: `业务员`, visible: true},
        {key: 4, label: `入款状态`, visible: true},
        {key: 5, label: `发货状态`, visible: true},
        {key: 6, label: `预计发货时间`, visible: true}
      ],
      // 表单校验
      rules: {}
    };
  },
  created() {

    //加载  销售
    if (window['SalesOption'] != undefined && window['SalesOption'] != null && window['SalesOption'] != '') {
      this.SalesOption = window['SalesOption'];
      this.SetAdminOption();
    } else {
      let map = {};
      map.isSales = 1;
      let Pwd_Str = tools.encrypt(JSON.stringify(map));
      findSalesPartner(Pwd_Str).then(response => {
        let jsonobj = JSON.parse(tools.Decrypt(response));
        if (jsonobj.code == 200) {
          window['SalesOption'] = jsonobj.Data;
          this.SalesOption = window['SalesOption'];
          //console.log(this.SalesOption)
          this.SetAdminOption();
        } else {
          this.msgError(jsonobj.msg);
        }
      })
    }

    //加载  总部门所有人
    if (window['HeadquartersOption'] != undefined && window['HeadquartersOption'] != null && window['HeadquartersOption'] != '') {
      this.HeadquartersOption = window['HeadquartersOption'];
      this.SetHeadquartersOption();
    } else {
      let map = {};
      map.isdept_id = 100;
      let Pwd_Str = tools.encrypt(JSON.stringify(map));
      findSalesPartner(Pwd_Str).then(response => {
        let jsonobj = JSON.parse(tools.Decrypt(response));
        if (jsonobj.code == 200) {
          window['HeadquartersOption'] = jsonobj.Data;
          this.HeadquartersOption = window['HeadquartersOption'];
          this.SetHeadquartersOption();
        } else {
          this.msgError(jsonobj.msg);
        }
      })
    }


    //加载 订单合同发货信息 合同性质
    if (window['contractNatureOption'] != undefined && window['contractNatureOption'] != null && window['contractNatureOption'] != '') {
      this.contractNatureOption = window['contractNatureOption'];
    } else {
      this.getDicts("contract_nature").then(response => {
        window['contractNatureOption'] = response.data;
        this.contractNatureOption = window['contractNatureOption'];
      });
    }

    //加载 发货状态
    if (window['ShipStateOption'] != undefined && window['ShipStateOption'] != null && window['ShipStateOption'] != '') {
      this.ShipStateOption = window['ShipStateOption'];
    } else {
      this.getDicts("Ship_state").then(response => {
        window['ShipStateOption'] = response.data;
        this.ShipStateOption = window['ShipStateOption'];
      });
    }


    //加载 入款状态
    if (window['Remittance_State'] != undefined && window['Remittance_State'] != null && window['Remittance_State'] != '') {
      this.Remittance_State = window['Remittance_State'];
    } else {
      this.getDicts("cwgl_Deposit_state").then(response => {
        window['Remittance_State'] = response.data;
        this.Remittance_State = window['Remittance_State'];
      });
    }


    //加载 查询条件
    if (window['OrderDelivery_selType'] != undefined && window['OrderDelivery_selType'] != null && window['OrderDelivery_selType'] != '') {
      this.typeOptions = window['OrderDelivery_selType'];
    } else {
      this.getDicts("yunze_OrderDelivery_selType").then(response => {
        window['OrderDelivery_selType'] = response.data;
        this.typeOptions = window['OrderDelivery_selType'];
      });
    }

    //加载 查询时间类型 条件
    if (window['OrderDelivery_timetype'] != undefined && window['OrderDelivery_timetype'] != null && window['OrderDelivery_timetype'] != '') {
      this.timetypeOptions = window['OrderDelivery_timetype'];
    } else {
      this.getDicts("yunze_OrderDelivery_timetype").then(response => {
        window['OrderDelivery_timetype'] = response.data;
        this.timetypeOptions = window['OrderDelivery_timetype'];
      });
    }

    //加载 客户一级分类
    if (window['CustomerOneCategoryOption'] != undefined && window['CustomerOneCategoryOption'] != null && window['CustomerOneCategoryOption'] != '') {
      this.CustomerOneCategoryOption = window['CustomerOneCategoryOption'];
    } else {
      this.getDicts("yz_customer_grade_one").then(response => {
        window['CustomerOneCategoryOption'] = response.data;
        this.CustomerOneCategoryOption = window['CustomerOneCategoryOption'];
      });
    }


    //加载 客户二级分类
    if (window['CustomerTowCategoryOption'] != undefined && window['CustomerTowCategoryOption'] != null && window['CustomerTowCategoryOption'] != '') {
      this.CustomerTowCategoryOption = window['CustomerTowCategoryOption'];
    } else {
      this.getDicts("yz_customer_grade_tow").then(response => {
        window['CustomerTowCategoryOption'] = response.data;
        this.CustomerTowCategoryOption = window['CustomerTowCategoryOption'];
      });
    }


    //加载 客户 级别
    if (window['CustomerGradeOption'] != undefined && window['CustomerGradeOption'] != null && window['CustomerGradeOption'] != '') {
      this.CustomerGradeOption = window['CustomerGradeOption'];
    } else {
      this.getDicts("yz_customer_grade").then(response => {
        window['CustomerGradeOption'] = response.data;
        this.CustomerGradeOption = window['CustomerGradeOption'];
      });
    }

    //加载 客户 来源
    if (window['CustomerSourceOptions'] != undefined && window['CustomerSourceOptions'] != null && window['CustomerSourceOptions'] != '') {
      this.CustomerSourceOptions = window['CustomerSourceOptions'];
    } else {
      this.getDicts("yz_customer_source").then(response => {
        window['CustomerSourceOptions'] = response.data;
        this.CustomerSourceOptions = window['CustomerSourceOptions'];
      });
    }


    //加载 大分类
    if (window['Large_classification'] != undefined && window['Large_classification'] != null && window['Large_classification'] != '') {
      this.Large_classification = window['Large_classification'];
      let map = {};
      map.Cy_Sort = '9';
      if (tools.Is_null(window['details_' + map.Cy_Sort])) {
        this.getTowClass({'Cy_Sort': window['details_' + map.Cy_Sort]});
      }
      this.commodity.Cy_Sort = this.Large_classification[0].CODE;
    } else {
      let map = {};
      map.Cy_Sort = '9';
      let Pwd_Str = tools.encrypt(JSON.stringify(map));
      Administration(Pwd_Str).then(response => {
        let jsonobj = JSON.parse(tools.Decrypt(response));
        window['Large_classification'] = jsonobj.Data;
        this.Large_classification = window['Large_classification'];
        if (this.Large_classification != null && this.Large_classification.length > 0) {
          let val = '';
          for (let i = 0; i < this.Large_classification.length; i++) {
            let obj = this.Large_classification[i];
            // console.log(obj)
            window['child_id_' + map.Cy_Sort + "_" + obj.CODE] = [];
            (window['child_id_' + map.Cy_Sort + "_" + obj.CODE]).push(obj.child_id);
            if (i == 0) {
              window['details_' + map.Cy_Sort] = obj.child_id;
            }
          }
          if (tools.Is_null(window['details_' + map.Cy_Sort])) {
            this.getTowClass({'Cy_Sort': window['details_' + map.Cy_Sort]});
            this.commodity.Cy_Sort = this.Large_classification[0].CODE;
          }
        }
      });
    }


    //加载 发货类型
    if (window['DeliveryTypeOption'] != undefined && window['DeliveryTypeOption'] != null && window['DeliveryTypeOption'] != '') {
      this.DeliveryTypeOption = window['DeliveryTypeOption'];
    } else {
      this.getDicts("Delivery_type").then(response => {
        window['DeliveryTypeOption'] = response.data;
        this.DeliveryTypeOption = window['DeliveryTypeOption'];
      });
    }

    //加载 发货选择类型
    if (window['DeliverySelectionTypeOption'] != undefined && window['DeliverySelectionTypeOption'] != null && window['DeliverySelectionTypeOption'] != '') {
      this.DeliverySelectionTypeOption = window['DeliverySelectionTypeOption'];
    } else {
      this.getDicts("Delivery_selection_type").then(response => {
        window['DeliverySelectionTypeOption'] = response.data;
        this.DeliverySelectionTypeOption = window['DeliverySelectionTypeOption'];
      });
    }


    //加载 发货方式
    if (window['DeliveryMethodOption'] != undefined && window['DeliveryMethodOption'] != null && window['DeliveryMethodOption'] != '') {
      this.DeliveryMethodOption = window['DeliveryMethodOption'];
    } else {
      this.getDicts("Delivery_method").then(response => {
        window['DeliveryMethodOption'] = response.data;
        this.DeliveryMethodOption = window['DeliveryMethodOption'];
      });
    }

    //加载 运费方式
    if (window['ShippingMethodOption'] != undefined && window['ShippingMethodOption'] != null && window['ShippingMethodOption'] != '') {
      this.ShippingMethodOption = window['ShippingMethodOption'];
    } else {
      this.getDicts("Shipping_method").then(response => {
        window['ShippingMethodOption'] = response.data;
        this.ShippingMethodOption = window['ShippingMethodOption'];
      });
    }


    //加载 快递公司信息
    if (window['CourierCompanyOptions'] != undefined && window['CourierCompanyOptions'] != null && window['CourierCompanyOptions'] != '') {
      this.CourierCompanyOptions = window['CourierCompanyOptions'];
      this.form.SAN_Express_Delivery = this.CourierCompanyOptions[0].EDY_ID;
    } else {
      ExpressSelDate(tools.encrypt(JSON.stringify({}))).then(response => {
        let jsonobj = JSON.parse(tools.Decrypt(response));
        window['CourierCompanyOptions'] = jsonobj.Data;
        this.CourierCompanyOptions = window['CourierCompanyOptions'];
        this.form.SAN_Express_Delivery = this.CourierCompanyOptions[0].EDY_ID;
      });
    }

    //条件查询 默认选择第一个
    this.queryParams.type = '1';

    // this.getTreeselect();
    this.getList();
    //tools.Element_edit();


  },
  methods: {


    //设置数据
    SetObj(Key, obj) {
      //console.log(obj);
      switch (Key) {
        case 'SetEditexecute':
          this.Editexecute = obj;//设置 发货申请 编辑  是否已经加载 [提供给子组件使用]
          break;
        case 'Setform':
          this.form = obj;// 设置 form
          break;
        case 'SetExecute':
          this.execute = obj;// 加载是否 已执行
          break;
        case 'Setdrawer':
          this.show_ds = obj;// 设置 drawer
          break;
      }
    },


    //设置管理员 选项
    SetHeadquartersOption() {
      if (this.HeadquartersOption != null && this.HeadquartersOption.length > 0) {
        this.HeadquartersnOrmalOption = [];
        let username = tools.getCookie("username");

        for (let i = 0; i < this.HeadquartersOption.length; i++) {
          let Obj = this.HeadquartersOption[i];
          if (Obj.del_flag == '0' && Obj.status == '0') {//获取 未删除的 状态正常的
            this.HeadquartersnOrmalOption.push(Obj);
            //选中当前登录用户信息
            //console.log(username == Obj.user_name);
            if (Obj.user_name == username) {
              this.form.SAN_UserID = Obj.user_id;
            }
          }
        }
      }
    },


    changOneClass(val) {
      let child_id = window['child_id_9_' + val];
      this.getTowClass({'Cy_Sort': child_id[0], "child_id_sel": val});
    },

    //获取二级分类
    getTowClass(map) {
      //加载 大分类
      if (window['TowClass' + map.Cy_Sort] != undefined && window['TowClass' + map.Cy_Sort] != null && window['TowClass' + map.Cy_Sort] != '') {
        this.Small_classification = window['TowClass' + map.Cy_Sort]
        this.commodity.Cy_Category = this.Small_classification[0].CODE;
      } else {
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        Administration(Pwd_Str).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          window['TowClass' + map.Cy_Sort] = jsonobj.Data;
          window['TowClasschildArr' + map.child_id_sel] = window['TowClass' + map.Cy_Sort];
          //console.log(jsonobj.Data)
          this.Small_classification = window['TowClass' + map.Cy_Sort]
          this.commodity.Cy_Category = this.Small_classification[0].CODE;
        });
      }
    },


    //选中 当前登录用户
    SetAdminOption() {
      if (this.SalesOption != null && this.SalesOption.length > 0) {
        this.AdminOption = [];
        //默认选择第一个
        this.form.c_party_b_phone = this.SalesOption[0].phonenumber;
        this.form.c_party_b_id = this.SalesOption[0].user_id;
        let username = tools.getCookie("username");
        for (let i = 0; i < this.SalesOption.length; i++) {
          let Obj = this.SalesOption[i];
          this.AdminOption.push(Obj);
          window["SalesOptionPhonenumber_" + Obj.user_id] = Obj.phonenumber;
          //选中当前登录用户信息
          //console.log(username == Obj.user_name);
          if (Obj.user_name == username) {
            this.form.c_party_b_phone = Obj.phonenumber;
            this.form.c_party_b_id = Obj.user_id;
            this.form.c_userId = Obj.user_id;
          }
        }
      }
    },

    //获取对应 class 颜色
    getColor(key) {
      var class_color = "";
      switch (key) {
        case 1:
          class_color = 'my_cloor_red';
          break;
        case 2:
          class_color = 'my_cloor_blue';
          break;
        default:
          class_color = 'my_cloor_black';
          break;
      }
      return class_color;
    },

    /*获取查询参数*/
    getParams() {
      if (tools.Is_null(this.queryParams.timetype) && this.selTime != null) {
        this.queryParams.staTime = this.selTime[0];
        this.queryParams.endTime = this.selTime[1];
      }
      //console.log(this.queryParams);
    },

    /** 查询 */
    getList() {
      this.loading = true;
      this.getParams();
      this.queryParams.page = 1;
      let Pwd_Str = tools.encrypt(JSON.stringify(this.queryParams));
      getList(Pwd_Str).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          if (jsonobj.code == 200) {
            //console.log(jsonobj)
            this.DataList = jsonobj.Data.Data;
            this.total = jsonobj.Data.Pu.rowCount;
          } else {
            this.msgError(jsonobj.msg);
          }
          this.loading = false;
        }
      );
    },


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {};
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.selTime = null;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },


    /** 表格 按钮操作 */
    handleUpdate(row, Operate) {
      //this.form = JSON.parse(JSON.stringify(row));
      //this.show_ds = true;
      // console.log(row);
      if (Operate == "Add") {//载入发货 申请

        //赋值 单位名称
        this.form.SAN_CoName = row.CoName;
        this.form.IsManual = '1';//手动填写
        this.form.IsManualBool = true;//手动填写

        this.form.Manual_SAN_Recipient_Address = row.c_party_a_address;//手动填写 地址
        this.form.Manual_SAN_Recipient_Tel = row.c_party_a_phone;//手动填写 收件人电话
        this.form.Manual_SAN_Recipient_Name = row.c_party_a_name;//手动填写 收件人

        this.form.SAN_Shipping_MethodArr = ['2'];
        this.form.SAFL_ODYContractID = row.ODY_Contract_ID;//赋值 合同编号
        this.execute = false;//加载是否 已执行
        this.show_ds = true;
        this.CustomerAdd = true;
        this.CustomerEdie = false;

      } else if (Operate == "Find") {
        this.CustomerAdd = false;
        this.CustomerEdie = false;
        this.Editexecute = false;
        this.getListID(row);
      }
    },

    /** 详情按钮操作 */
    ViewDetails(row) {
      //console.log(row);
      this.form = {};//清空数据
      this.CustomerAdd = false;
      this.CustomerEdie = false;
      this.form = JSON.parse(JSON.stringify(row));
      //this.show_ds = true;
    },

    /** 发货申请详情 */
    getListID(row) {
      let map = {};
      map.SAFL_ODYContractID = row.ODY_Contract_ID;
      //console.log(map)
      let Pwd_Str = tools.encrypt(JSON.stringify(map));
      getODYContractID(Pwd_Str).then(response => {
        let jsonobj = JSON.parse(tools.Decrypt(response));
        if (jsonobj.Data != null && jsonobj.Data != '') {
          //console.log(jsonobj)
          if (jsonobj.code == 200) {
            this.SAFL_SANIDArr = jsonobj.Data
            this.show_dsArr = true;
            this.msgSuccess();
          } else {
            let msg = jsonobj.Data != null && jsonobj.Data != '' ? jsonobj.Data : jsonobj.msg;
            this.msgError(msg);
          }
        } else {
          this.show_dsArr = false;
          this.msgError("该数据为空");
        }
        this.loading = false;
      });


    },


    /*获取详细信息*/
    finddata(row) {
      let map = {};
      map.id = row.id;
      map.Csd_CtID = row.code;
      let Pwd_Str = tools.encrypt(JSON.stringify(map));
      find(Pwd_Str).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          if (jsonobj.code == 200) {
            let CMap = jsonobj.Data.CMap;
            // 数据格式化
            CMap.c_party_b_id = Number(CMap.c_party_b_id);
            CMap.c_brId = "" + CMap.c_brId;
            //CMap.c_id = ""+CMap.c_id;
            CMap.c_fatId = "" + CMap.c_fatId;
            CMap.profit_sharing = "" + CMap.profit_sharing;
            this.CommodityList = jsonobj.Data.standardList;
            //赋值 查询条件为 当前 用户名 加载客户信息
            this.Sel.c_name = CMap.c_name;
            let SelMap = {};
            SelMap.Sel_c_party_a_name = CMap.c_party_a_name;
            SelMap.Sel_c_party_a_address = CMap.c_party_a_address;
            SelMap.Sel_c_name = CMap.c_name;
            this.setCustomerArr(SelMap);


            /* //根据 名称 选中
             let vleue = 'NAME';
             let key = 'id';
             let text = this.form.c_party_a_name;
             console.log(this.PeopleOption)
             for (let i = 0; i < this.PeopleOption.length(); i++) {
               let obj = this.PeopleOption[i]
               if(obj.key==text){
                 this.form.c_party_a_id = obj.vleue;
                 console.log(" get key "+obj.vleue)
               }
             }*/


            this.form = CMap;
            this.show_ds = true;
          } else {
            this.msgError(jsonobj.msg);
          }
          this.loading = false;
        }
      );
    },
    SubAdd(map) {
      let Pwd_Str = tools.encrypt(JSON.stringify(map));
      add(Pwd_Str).then(response => {
        let jsonobj = JSON.parse(tools.Decrypt(response));
        //console.log(jsonobj);
        if (jsonobj.code == 200) {
          this.msgSuccess(jsonobj.msg);
          this.show_ds = false;
          //更新数据
          this.queryParams.page = 1;
          this.getList();
        } else {
          let msg = jsonobj.Data != null && jsonobj.Data != '' ? jsonobj.Data : jsonobj.msg;
          this.msgError(msg);
        }
      })
    },

    //编辑
    Edie() {
      let _this = this;
      //console.log(this.CommodityList_delArr)
      if (
        tools.VerificationsText(_this, _this.form.c_id, "请根据筛选条件查询并选择企业信息！") == true &&
        tools.VerificationsText(_this, _this.form.c_fatId, "请选择销售单位！") == true &&
        tools.VerificationsText(_this, _this.form.c_party_a_id, "请选择 甲方代表！") == true &&
        tools.VerificationsText(_this, _this.form.c_party_a_address, "请选择 甲方地址！") == true &&
        tools.VerificationsText(_this, _this.form.id, "必要参数缺失请刷新后重试！") == true &&
        tools.VerificationsText(_this, _this.form.c_time, "请选择 合同日期！") == true) {


        // 获取 c_name 客户名称  c_fatName 销售单位名称 c_userName 销售名称 c_party_a_name 甲方代表 c_party_b_name 已方代表
        this.form.c_name = tools.getkeyValue(this.CustomerOption, this.form.c_id, "id", "c_name");
        this.form.c_fatName = tools.getkeyValue(this.firmAccountOption, this.form.c_fatId, "Fat_ID", "Fat_Name");
        this.form.c_userName = tools.getkeyValue(this.SalesOption, this.form.c_userId, "user_id", "nick_name");
        this.form.c_party_a_name = tools.getkeyValue(this.PeopleOption, this.form.c_party_a_id, "id", "NAME");
        this.form.c_party_b_name = tools.getkeyValue(this.SalesOption, this.form.c_party_b_id, "user_id", "nick_name");

        //console.log(this.form);
        //console.log(this.CommodityList);
        if (this.CommodityList != null && this.CommodityList.length > 0) {
          console.log("SubUpd");
          this.SubUpd();
        } else {
          tools.open(this, "请选择合同商品 信息！");
        }

      }
    },
    SubUpd() {
      let map = {};
      map.CMap = this.form;
      map.Csd_CtID = this.form.code;
      map.code = this.form.id;

      map.standardList = this.CommodityList;
      map.CommodityList_delArr = this.CommodityList_delArr;
      //console.log(map);
      let Pwd_Str = tools.encrypt(JSON.stringify(map));
      upd(Pwd_Str).then(response => {
        let jsonobj = JSON.parse(tools.Decrypt(response));
        //console.log(jsonobj);
        if (jsonobj.code == 200) {
          this.msgSuccess(jsonobj.msg);
          this.show_ds = false;
          //更新数据
          this.form.dept_id = '';
          this.form.c_name = '';
          this.queryParams.page = 1;
          this.getList();
        } else {
          let msg = jsonobj.Data != null && jsonobj.Data != '' ? jsonobj.Data : jsonobj.msg;
          this.msgError(msg);
        }
      })

    },


  }
};
</script>


<style scoped>
.my_cloor_red {
  background-color: #e64242;
  color: white;
}

.my_cloor_blue {
  background-color: #1682e6;
  color: white;
}

.my_cloor_Orange {
  background-color: #303133;
  color: white;
}

.my_cloor_black {
  background-color: #303133;
  color: white;
}

</style>


